# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gnupg
pkgver=2.2.21
_ver=${pkgver/_beta/-beta}
pkgrel=0
pkgdesc="GNU Privacy Guard 2 - a PGP replacement tool"
url="https://www.gnupg.org/"
arch="all"
license="GPL-3.0-or-later"
depends="pinentry"
makedepends="gnutls-dev libksba-dev libgcrypt-dev libgpg-error-dev
	npth-dev zlib-dev libassuan-dev openldap-dev bzip2-dev
	sqlite-dev libusb-dev"
subpackages="$pkgname-doc $pkgname-scdaemon"
source="https://gnupg.org/ftp/gcrypt/gnupg/gnupg-$_ver.tar.bz2
	0001-Include-sys-select.h-for-FD_SETSIZE.patch
	fix-i18n.patch
	60-scdaemon.rules
	"
install="$pkgname-scdaemon.pre-install"

# secfixes:
#   2.2.18-r0:
#     - CVE-2019-14855
#   2.2.8-r0:
#     - CVE-2018-12020

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--disable-nls \
		--enable-bzip2 \
		--enable-tofu \
		--enable-scdaemon \
		--enable-ccid-driver
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	# install compat symlink
	ln -s gpg  "$pkgdir"/usr/bin/gpg2
	ln -s gpgv "$pkgdir"/usr/bin/gpgv2

	install -m755 tools/gpg-zip "$pkgdir"/usr/bin/gpg-zip

	# Remove docs for systemd-user
	rm -rf "$pkgdir"/usr/share/doc/gnupg/examples/systemd-user
}

scdaemon() {
	pkgdesc="GNU Privacy Guard 2 - smart card support"
	depends="gnupg"

	mkdir -p "$subpkgdir/usr/libexec"
	mkdir -p "$subpkgdir/lib/udev/rules.d"

	install -Dm644 -t "$subpkgdir/lib/udev/rules.d/" \
		"$srcdir/60-scdaemon.rules"
	mv "$pkgdir/usr/libexec/scdaemon" "$subpkgdir/usr/libexec/"
}

sha512sums="b4eac75253d4a1cac341c8a1ba7bb275e849a88d5377035497777c7bcd49b5a4c91b77000311695eb7d4083856975b2b2d14518f24ab94846027280bd8c301f9  gnupg-2.2.21.tar.bz2
c6cc4595081c5b025913fa3ebecf0dff87a84f3c669e3fef106e4fa040f1d4314ee52dd4c0e0002b213034fb0810221cfdd0033eae5349b6e3978f05d08bcac7  0001-Include-sys-select.h-for-FD_SETSIZE.patch
b19a44dacf061dd02b439ab8bd820e3c721aab77168f705f5ce65661f26527b03ea88eec16d78486a633c474120589ec8736692ebff57ab9b95f52f57190ba6b  fix-i18n.patch
4bfb9742279c2d1c872d63cd4bcb01f6a2a13d94618eff954d3a37451fa870a9bb29687330854ee47e8876d6e60dc81cb2569c3931beaefacda33db23c464402  60-scdaemon.rules"
